home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------
- //
- // Module:
- // TupleDumper.c
- //
- // Purpose:
- // Use the PCCardFPI interface to dump tuples of any inserted cards
- //
- // Author:
- // Dave Tarabar
- //
- // Copyright: © 1996 SystemSoft Corporation, all rights reserved.
- //----------------------------------------------------------------------
-
- #include <stdio.h>
- #include <DriverSupport.h>
- #include <Errors.h>
- #include <PCCard.h>
- #include <PCCardTuples.h>
- #include <TextUtils.h>
-
- //----------
- void ByteToChars(UInt8 inByte, char* leftChar, char* rightChar);
- void FormatTheTuple(UInt8 tupleCode, UInt16 len, char* tupleBody, char* buffer);
- OSErr PostNotification(Str255 msg, OSErr errCode);
- OSStatus DumpTheTuples(const RegEntryRef * cardRef);
-
-
- //--------------------------------------------------------------------------------
- void main()
- {
- OSStatus err;
- ItemCount socketCount;
- UInt32 complianceLevel, version;
- PCCardSocket i;
- RegEntryRef cardRef;
-
- // how many socket are there
- err = PCCardGetCardServicesInfo(&socketCount, &complianceLevel, &version);
- if (err != noErr)
- PostNotification("\pPCCardGetCardServicesInfo failed", err);
-
- // loop through all of the sockets, looking for cards
- for (i = 0; i < socketCount; i++)
- {
- err = PCCardGetCardRef(i, &cardRef);
- if (err == noErr)
- {
- // found a card, dump it's tuples
- printf("Card in Socket %d\n\n", i);
- DumpTheTuples(&cardRef);
- printf("\n");
- }
- }
- }
-
-
- //--------------------------------------------------------------------------------
- OSStatus DumpTheTuples(const RegEntryRef * cardRef)
- {
- OSStatus err;
- PCCardTupleIterator tupleIterator;
- Byte buffer[MAX_TUPLE_SIZE];
- char outBuffer[1500]; // big enough ??
- UInt32 bufferSize, tupleSize;
- PCCardTupleKind foundTuple;
-
- // allocate a tuple iterator
- tupleIterator = PCCardNewTupleIterator();
- if (tupleIterator == NULL)
- return memFullErr;
-
- // get the first tuple
- bufferSize = MAX_TUPLE_SIZE;
- err = PCCardGetFirstTuple(cardRef, 0xFF, tupleIterator, buffer, &bufferSize, &foundTuple, &tupleSize);
-
- while (err == noErr)
- {
- // output the current tuple
- FormatTheTuple(foundTuple, tupleSize, (char *) buffer, outBuffer);
- printf (outBuffer);
-
- // get the next tuple
- bufferSize = MAX_TUPLE_SIZE;
- err = PCCardGetNextTuple(cardRef, 0xFF, tupleIterator, buffer, &bufferSize, &foundTuple, &tupleSize);
- }
-
- // that's all folks
- (void) PCCardDisposeTupleIterator(tupleIterator);
- return noErr;
- }
-
-
- //--------------------------------------------------------------------------------
- // do a hex dump of a tuple with the 1 byte code, a space & then a dump of the data
- void FormatTheTuple(UInt8 tupleCode, UInt16 len, char* tupleBody, char* buffer)
- {
- short count = 0, i;
- char foo, bar;
-
- ByteToChars(tupleCode, &foo, &bar);
- buffer[count++] = foo;
- buffer[count++] = bar;
- buffer[count++] = ' ';
- buffer[count++] = 0;
-
- switch (tupleCode)
- {
- case CISTPL_NULL:
- CStrCat(buffer, "CISTPL_NULL ");
- break;
- case CISTPL_DEVICE:
- CStrCat(buffer, "CISTPL_DEVICE ");
- break;
- case CISTPL_LONGLINK_CB:
- CStrCat(buffer, "CISTPL_LONGLINK_CB ");
- break;
- case CISTPL_INDIRECT:
- CStrCat(buffer, "CISTPL_INDIRECT ");
- break;
- case CISTPL_LONGLINK_MFC:
- CStrCat(buffer, "CISTPL_LONGLINK_MFC ");
- break;
- case CISTPL_CHECKSUM:
- CStrCat(buffer, "CISTPL_CHECKSUM ");
- break;
- case CISTPL_LONGLINK_A:
- CStrCat(buffer, "CISTPL_LONGLINK_A ");
- break;
- case CISTPL_LONGLINK_C:
- CStrCat(buffer, "CISTPL_LONGLINK_C ");
- break;
- case CISTPL_LINKTARGET:
- CStrCat(buffer, "CISTPL_LINKTARGET ");
- break;
- case CISTPL_NO_LINK:
- CStrCat(buffer, "CISTPL_NO_LINK ");
- break;
- case CISTPL_VERS_1:
- CStrCat(buffer, "CISTPL_VERS_1 ");
- break;
- case CISTPL_ALTSTR:
- CStrCat(buffer, "CISTPL_ALTSTR ");
- break;
- case CISTPL_DEVICE_A:
- CStrCat(buffer, "CISTPL_DEVICE_A ");
- break;
- case CISTPL_JEDEC_C:
- CStrCat(buffer, "CISTPL_JEDEC_C ");
- break;
- case CISTPL_JEDEC_A:
- CStrCat(buffer, "CISTPL_JEDEC_A ");
- break;
- case CISTPL_CONFIG:
- CStrCat(buffer, "CISTPL_CONFIG ");
- break;
- case CISTPL_CFTABLE_ENTRY:
- CStrCat(buffer, "CISTPL_CFTABLE_ENTRY ");
- break;
- case CISTPL_DEVICE_OC:
- CStrCat(buffer, "CISTPL_DEVICE_OC ");
- break;
- case CISTPL_DEVICE_OA:
- CStrCat(buffer, "CISTPL_DEVICE_OA ");
- break;
- case CISTPL_DEVICE_GEO:
- CStrCat(buffer, "CISTPL_DEVICE_GEO ");
- break;
- case CISTPL_DEVICE_GEO_A:
- CStrCat(buffer, "CISTPL_DEVICE_GEO_A ");
- break;
- case CISTPL_MANFID:
- CStrCat(buffer, "CISTPL_MANFID ");
- break;
- case CISTPL_FUNCID:
- CStrCat(buffer, "CISTPL_FUNCID ");
- break;
- case CISTPL_FUNCE:
- CStrCat(buffer, "CISTPL_FUNCE ");
- break;
- case CISTPL_SWIL:
- CStrCat(buffer, "CISTPL_SWIL ");
- break;
- case CISTPL_VERS_2:
- CStrCat(buffer, "CISTPL_VERS_2 ");
- break;
- case CISTPL_FORMAT:
- CStrCat(buffer, "CISTPL_FORMAT ");
- break;
- case CISTPL_GEOMETRY:
- CStrCat(buffer, "CISTPL_GEOMETRY ");
- break;
- case CISTPL_BYTEORDER:
- CStrCat(buffer, "CISTPL_BYTEORDER ");
- break;
- case CISTPL_DATE:
- CStrCat(buffer, "CISTPL_DATE ");
- break;
- case CISTPL_BATTERY:
- CStrCat(buffer, "CISTPL_BATTERY ");
- break;
- case CISTPL_ORG:
- CStrCat(buffer, "CISTPL_ORG ");
- break;
- case CISTPL_VENDOR:
- CStrCat(buffer, "CISTPL_VENDOR ");
- break;
- case CISTPL_END:
- CStrCat(buffer, "CISTPL_END ");
- break;
-
- default:
- CStrCat(buffer, "???? ");
- break;
-
- }
-
- count = CStrLen(buffer);
- for (i=0; i<len; i++)
- {
- ByteToChars(tupleBody[i], &foo, &bar);
- buffer[count++] = foo;
- buffer[count++] = bar;
- }
- buffer[count++] = 0;
-
- // print out the ascii of manufacturer and card name for CISTPL_VERS_1
- if (tupleCode == CISTPL_VERS_1)
- {
- CStrCat(buffer,"\n manufacturer = ");
- CStrCat(buffer, (const char *) &tupleBody[2]);
- CStrCat(buffer,"\n card name = ");
- for (i=2; (tupleBody[i] != 0) && (i < CStrLen(tupleBody)); i++) {}
- i++;
- CStrCat(buffer, (const char *) &tupleBody[i]);
- }
-
- // print out an ascii name of device type for CISTPL_FUNCID
- if (tupleCode == CISTPL_FUNCID)
- {
- CStrCat(buffer,"\n type = ");
- switch (tupleBody[0])
- {
- case TPLFID_MultiFunction:
- CStrCat(buffer, "multi-function card");
- break;
- case TPLFID_Memory:
- CStrCat(buffer, "memory card");
- break;
- case TPLFID_SerialPort:
- CStrCat(buffer, "serial port or modem");
- break;
- case TPLFID_ParallelPort:
- CStrCat(buffer, "parallel port");
- break;
- case TPLFID_FixedDisk:
- CStrCat(buffer, "fixed disk");
- break;
- case TPLFID_VideoAdapter:
- CStrCat(buffer, "video adapter");
- break;
- case TPLFID_NetworkLANAdapter:
- CStrCat(buffer, "network adapter");
- break;
- case TPLFID_AIMS:
- CStrCat(buffer, "AIMS");
- break;
- case TPLFID_SCSI:
- CStrCat(buffer, "SCSI");
- break;
- default:
- CStrCat(buffer, "????");
- break;
- }
- }
- CStrCat(buffer, "\n");
- CStrCat(buffer, "\0");
- }
-
-
- //--------------------------------------------------------------------------------
- // convert the input byte to the two characters of it's hexadecimal representation
- void ByteToChars(UInt8 inByte, char* leftChar, char* rightChar)
- {
- static char trans[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- short R = inByte & 0x0F;
- short L = (inByte & 0xF0) >> 4;
-
- *leftChar = trans[L];
- *rightChar = trans[R];
- }
-
-
- //--------------------------------------------------------------------------------
- // Notify some one that an error has occurred.
- OSErr PostNotification(Str255 msg, OSErr errCode)
- {
- Str255 gNotifyAlertText;
-
- // build an appropriate text string for the alert
- PStrCopy(gNotifyAlertText, msg);
- if (errCode != noErr)
- {
- Str31 errText;
-
- NumToString(errCode, errText);
- PStrCat(gNotifyAlertText, "\p, code = ");
- PStrCat(gNotifyAlertText, errText);
- }
- DebugStr(gNotifyAlertText);
-
- return noErr;
- }
-
-